public class Solution468 {
    public String validIPAddress(String queryIP) {
        if (queryIP.indexOf(".")*queryIP.indexOf(":")>=0){
            return "Neither";
        }else if (queryIP.indexOf(".")>0){
            String[] strings=queryIP.split("\\.");
            if (strings.length!=4 || queryIP.endsWith(".")){
                return "Neither";
            }else{
                for (int i=0;i<4;i++){
                    String temp=strings[i];
                    if (temp.length()==0 || temp.length()>3 || temp.startsWith("0")&&temp.length()>1){
                        return "Neither";
                    }
                    for (char c : temp.toCharArray()) {
                        if (!(c>='0' && c<='9')){
                            return "Neither";
                        }
                    }
                    int t=Integer.parseInt(temp);
                    if (t>255){
                        return "Neither";
                    }
                }
                return "IPv4";
            }
        }else{
            String[] strings=queryIP.split(":");
            if (strings.length!=8 || queryIP.endsWith(":")){
                return "Neither";
            }else{
                for (int i=0;i<8;i++){
                    String temp=strings[i];
                    if (temp.length()==0 || temp.length()>4){
                        return "Neither";
                    }
                    for (char c : temp.toCharArray()) {
                        if (!(c>='0' && c<='9' || c>='a' && c<='f' || c>='A' && c<='F')){
                            return "Neither";
                        }
                    }
                }
                return "IPv6";
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution468().validIPAddress("2001:0db8:85a3:0:0:8A2E:0370:7334:"));
    }
}
